import requests
from lxml import etree
import ddddocr
if __name__ == '__main__':
    url = 'https://www.bbiquge.net/login.php'
    headers = {
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.54'
    }
    page_text = requests.get(url=url,headers=headers).text
    tree = etree.HTML(page_text)
    img_src = tree.xpath('//*[@id="main"]/div[1]/form/fieldset/p[3]/img/@src')[0]
    img_src_url = 'https://www.bbiquge.net/'+img_src
    img_data = requests.get(url=img_src_url,headers=headers).content
    with open('./coding.jpg','wb') as fp :
        fp.write(img_data)
        pass
    ocr = ddddocr.DdddOcr()
    with open('./coding.jpg','rb') as f :
        res = f.read()
        pass
    result = ocr.classification(res)
    print('图片结果为：',result)
    headers2 = {
        'cookie':'Hm_lvt_007bc30c1abb0ffb7a93b4f3c8e10c5e=1672741872; PHPSESSID=bcr8hsa22osj3rvl92guhkpg2j; jieqiUserInfo=jieqiUserId%3D63317%2CjieqiUserUname%3D2523810765%2CjieqiUserName%3D%B9%CA%CA%C2%C0%EF%B5%C4%B4%F3%C4%A7%CD%F5%2CjieqiUserGroup%3D3%2CjieqiUserGroupName%3D%C6%D5%CD%A8%BB%E1%D4%B1%2CjieqiUserVip%3D0%2CjieqiUserHonorId%3D%2CjieqiUserHonor%3D%D0%C2%CA%D6%C9%CF%C2%B7%2CjieqiUserUname_un%3D2523810765%2CjieqiUserName_un%3D%26%23x6545%3B%26%23x4E8B%3B%26%23x91CC%3B%26%23x7684%3B%26%23x5927%3B%26%23x9B54%3B%26%23x738B%3B%2CjieqiUserHonor_un%3D%26%23x65B0%3B%26%23x624B%3B%26%23x4E0A%3B%26%23x8DEF%3B%2CjieqiUserGroupName_un%3D%26%23x666E%3B%26%23x901A%3B%26%23x4F1A%3B%26%23x5458%3B%2CjieqiUserLogin%3D1672743162; jieqiVisitInfo=jieqiUserLogin%3D1672743162%2CjieqiUserId%3D63317; Hm_lpvt_007bc30c1abb0ffb7a93b4f3c8e10c5e=1672743281'
    }
    detail_url = 'https://www.bbiquge.net/userdetail.php'
    detail_page = requests.get(url=detail_url,headers=headers2).text
    with open('./笔趣阁.html','w',encoding='utf-8') as fp:
        fp.write(detail_page)